var ExpensePage = {
	'queryByCondition': function() {
		findExpenseInfoAjax.setData({
			'rows': 999,
			'page': 1
		}).send();
		
		setTimeout(function() {
			findStatisticInfoAjax.send();
		}, 500);
	},
	'buildItem' : function(item, $container, index) {
		var $item = $("<div class='t-item'></div>");
		
		// 构造图标，表达：序号，渠道
		var $icon = $("<i class='t-expse-icon'></i>").text(index);
		if (item.consumeChannel == '01') {
			$icon.css("background-color", '#22be4c');
		}
		if (item.consumeChannel == '02') {
			$icon.css("background-color", '#ff7f27');
		} 
		$item.append($icon);
		
		// 第二列
		var $nameGroup = $("<div class='t-v-group'></div>");
		
		// 商品名称节点
		var $nameEle = $("<div class='t-name-element'></div>");
		$nameEle.text(item.productName);
		
		// 消费地点节点
		var $addressEle = $("<div class='t-address-element'></div>");
		$addressEle.text(codeSet.consumeAddress[item.consumeAddress]);
		
		var $consumeTypEle = $("<div class='t-type-element'></div>");
		$consumeTypEle.text(codeSet.consumeType[item.consumeType]);
		
		var $remarkEle = $("<div class='t-remark-element'></div>");
		var remark = StringUtil.isBlank(item.remark) ? "--": item.remark;
		$remarkEle.text(remark);
		
		$consumeTimeEle = $("<div class='t-time-element'></div>");
		$consumeTimeEle.text(item.consumeTime);
		
		$nameGroup.append($nameEle);
		$nameGroup.append($addressEle);
		$nameGroup.append($consumeTypEle);
		$nameGroup.append($remarkEle);
		
		var $priceGroup = $("<div class='t-v-group m-float-right'></div>");
		
		var $priceEle = $("<div class='t-price-element'></div>");
		$priceEle.text(item.consumeAmount);
		
		$priceGroup.append($consumeTimeEle);
		$priceGroup.append($priceEle);
		
		$item.append($nameGroup);
		$item.append($priceGroup);
		
		$container.append($item);
		return $item;
	},
	'onFindExpenseInfoSucc': function(data, status, xhr) {
		var info = data.info.data;
		var $container = $("[data-tag='expense-record']").find(".t-container");
		$container.empty();
		$.each(info, function(index, item) {
			ExpensePage.buildItem(item, $container, (index+1));
		});
	},
	'expenseAdd': function() {
		window.location.href = ctx + '/expense/add/index';
	},
	'delete': function(ele) {
		var id = $(ele).data("id");
		var productName = $(ele).data("productname");
		MsgBox.confirm("确认删除消费记录【" + productName + "】吗？", null, function() {
            deleteByIdAjax.tempUrl(function(url) {
                return url + id;
            }).send();
        });
	},
	'onDeleteSucc': function(data, status,xhr) {
		$.messager.info(data.message);
		this.queryByCondition();
	},
	'findStatisticInfoSucc': function(data, status, xhr) {
		$("#expenseFrm").find("[data-tag='statistic']").autofill(data.info);
	}
};